package net.jonbuck.tassoo.persistence.dao.util;

import net.jonbuck.tassoo.model.Container;
import net.jonbuck.tassoo.model.TassooPackage;
import net.jonbuck.tassoo.persistence.dao.TassooDao;

import org.eclipse.emf.query.conditions.eobjects.structuralfeatures.EObjectAttributeValueCondition;
import org.eclipse.emf.query.conditions.eobjects.structuralfeatures.EObjectReferenceValueCondition;
import org.eclipse.emf.query.conditions.strings.StringValue;
import org.eclipse.emf.query.statements.FROM;
import org.eclipse.emf.query.statements.IQueryResult;
import org.eclipse.emf.query.statements.SELECT;
import org.eclipse.emf.query.statements.WHERE;

/**
 * 
 * 
 * @since 1.0.0
 */
public class TassooStatisticsHelperUtil {

	/**
	 * 
	 * @param statusvalue
	 * @return
	 */
	public static int getTaskNumberByStatus(TassooDao tassooDao, Container container, String status) {
		int rValue = 0;
		SELECT statement = new SELECT(new FROM(container.getTask()), new WHERE(new EObjectReferenceValueCondition(
				TassooPackage.eINSTANCE.getTask_Status(), new EObjectAttributeValueCondition(
						TassooPackage.eINSTANCE.getReferenceModel_Value(), new StringValue(status)))));
		IQueryResult result = statement.execute();
		if (result.getException() == null) {
			if (!result.isEmpty()) {
				rValue = result.size();
			}
		}
		return rValue;
	}

}
